package com.pyound.utils;

import lombok.Data;

/**
 * 返回数据
 *
 * @author Mark sunlightcs@gmail.com
 */
@Data
public class R<T> {

    private Integer code;
    private String msg;
    private T data;

    public R() {
        this.code = 0;
        this.msg = "success";
    }

    public static R ok() {
        R r = new R();
        r.code = 200;
        return r;
    }


    public static R ok(Integer code, String msg) {
        R r = new R();
        r.code = code;
        r.msg = msg;
        return r;
    }


    public static <T> R<T> ok(T data) {
        R r = new R();
        r.code = 200;
        r.data = data;
        return r;
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.code = code;
        r.msg = msg;
        return r;
    }

    public static R error(String msg) {
        R r = new R();
        r.code = 40001;
        r.msg = msg;
        return r;
    }

}